package com.gitee.wsl.doc.prosemirror.collab

import com.gitee.wsl.doc.prosemirror.plugin.Plugin
import com.gitee.wsl.doc.prosemirror.plugin.PluginKey
import kotlin.random.Random

val collabKey = PluginKey<CollabState>("collab")


class CollabPlugin(
    override val spec: CollabPluginSpec
) : Plugin<CollabState>(spec) {
    constructor(config: CollabConfig) : this(
        CollabPluginSpec(
            CollabConfig(
                version = config.version,
                clientID = config.clientID ?: Random.Default.nextInt().toString()
            )
        )
    )

    override fun toString(): String {
        return "CollabPlugin: ${spec.config}"
    }
}